<template>
	<view :style="themeColor">
		<view class="page">
			<view class="flex benben-position-layout flex flex-wrap align-center rateLearn_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between flex-sub rateLearn_fd0_0'>
					<view class='flex flex-wrap align-center rateLearn_fd0_0_c0' @tap.stop="handleJumpDiy"
						data-type="back" data-url="1">
						<text class='fu-iconfont2  rateLearn_fd0_0_c0_c0'>&#xE794;</text>
					</view>
					<view class='flex flex-wrap align-stretch justify-center'>
						<text class='rateLearn_fd0_0_c1_c0'>我的收藏</text>
					</view>
					<view class='flex flex-wrap align-center justify-end rateLearn_fd0_0_c0' @tap.stop="edit">
						<text class="title_text" v-if="!is_edit">编辑</text>
						<text class="title_text" v-else>完成</text>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			<view class="loading_css" v-if="isShow">
				<u-loading size="36" color="#E60012"></u-loading>
				<view>加载中</view>
			</view>
			<!---flex布局flex布局开始-->
			<view class="flex benben-flex-layout flex-wrap align-center rateLearn_flex_3" v-else>
				<view class="flex flex-wrap align-center" v-for="(item,index) in list" :key="index" @tap.stop="handleJumpDiy" data-type="navigateTo" :data-url="`/pages/homePage/courseDetail/courseDetail?id=${item.course_id}`">
					<view class="select_icon" @tap.stop="selectContent(index)" v-if="is_edit">
						<image v-if="item.isSelect" :src='STATIC_URL+"140.png"' mode="aspectFill"></image>
						<image v-else :src='STATIC_URL+"141.png"' mode="aspectFill"></image>
					</view>
					<view class='flex align-center flex-sub rateLearn_fd3_0'>
						<view class='flex flex-wrap align-center rateLearn_fd3_0_c0'>
							<image class='rateLearn_fd3_0_c0_c1' mode="aspectFill" :src='item.thumb'></image>
						</view>
						<view class='flex flex-direction flex-wrap align-stretch flex-sub rateLearn_fd3_0_c1'>
							<view class='flex flex-wrap align-center flex-sub'>
								<text class='rateLearn_fd3_0_c1_c0_c0'>{{item.title}}</text>
							</view>
							<view class='flex flex-wrap align-center rateLearn_fd3_0_c1_c1'>
								<text class='rateLearn_fd3_0_c1_c1_c0'>讲师名称：{{item.lecturer}}</text>
								<text class='flex  rateLearn_fd3_0_c1_c1_c1'></text>
								<text class='rateLearn_fd3_0_c1_c1_c0'>{{item.course_hour}}课时</text>
							</view>
						</view>
					</view>
				</view>
				
				<view class="loadmore" v-if="last_page > 1">
					<u-loadmore font-size="24" :status="status" :icon-type="iconType" :load-text="loadText" />
				</view>
			</view>
			
			<view class="noData" v-if="list.length == 0 && !isShow">
				<image :src='STATIC_URL+"no.png"'></image>
			</view>
			<view class="total_info" v-if="is_edit">
				<view class="total_le" @tap.stop="changeTotal">
					<image v-if="isTotal" :src='STATIC_URL+"140.png"' mode="aspectFill"></image>
					<image v-else :src='STATIC_URL+"141.png"' mode="aspectFill"></image>
					<text>全选</text>
				</view>
				<view class="total_ri" @tap.stop="delBtn">删除</view>
			</view>
			<view v-if="is_edit" style="height: 100rpx;"></view>
		</view>
	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'

	export default {
		components: {},

		data() {
			return {
				"list": [],
				"page": 1,
				"is_pull": true,
				"last_page": 1,
				"status": 'loadmore',
				"iconType": 'flower',
				"loadText": {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '我也是有底线的'
				},
				"isShow": true,
				"is_edit": false,
				"isTotal": false,
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			this.getList();
		},
		onHide() {

		},
		onResize() {

		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			this.getList();
		},
		// 上拉加载
		onReachBottom() {
			if (this.page >= this.last_page) return;
			this.status = 'loading';
			this.page++;
			setTimeout(() => {
		
				if (this.page >= this.last_page) this.status = 'nomore';
				else this.status = 'loading';
				this.is_pull = false;
				this.getList();
			}, 500)
		},
		onPageScroll(e) {

		},
		methods: {
			getList() {
				this.$api.post(global.apiUrls.post65dda2c3cea0b, {
					page: this.page
				}).then(res => {
					// console.log(res);
					uni.stopPullDownRefresh();
					this.isShow = false;
					if (res.data.code == 1) {
						this.last_page = res.data.data.last_page;
						let list = res.data.data.data;
						if (list.length > 0) {
							list.forEach((v, k) => {
								v.isSelect = false;
							})
						}
						if (this.is_pull) {
							this.list = list;
						} else {
							this.list = this.list.concat(list);
						}
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			edit() {
				this.is_edit = !this.is_edit;
			},
			selectContent(index) {
				this.list[index].isSelect = !this.list[index].isSelect;
				let num = 0;
				num = this.list.filter(u => !u.isSelect).length;
				if (num == 0) {
					this.isTotal = true;
				} else {
					this.isTotal = false;
				}
				this.$forceUpdate();
			},
			changeTotal() {
				if (this.list.length == 0) return;
				this.isTotal = !this.isTotal;
				if (this.isTotal) {
					if (this.list.length > 0) {
						this.list.forEach((v, k) => {
							v.isSelect = true;
						})
					}
				} else {
					if (this.list.length > 0) {
						this.list.forEach((v, k) => {
							v.isSelect = false;
						})
					}
				}
				this.$forceUpdate();
			},
			delBtn() {
				let num = 0;
				num = this.list.filter(u => u.isSelect).length;
				if (num == 0) {
					this.$message.info('请选择课程');
					return;
				}
				let ids = [];
				this.list.forEach((v, k) => {
					if (v.isSelect) {
						ids.push(v.aid);
					}
				})
				this.$api.post(global.apiUrls.post65dda3e9c76b5, {
					id: ids.join(',')
				}).then(res => {
					this.$message.info(res.data.msg);
					if (res.data.code == 1) {
						this.is_edit = false;
						this.isTotal = false;
						this.page = 1;
						this.is_pull = true;
						this.isShow = true;
						this.getList();
					}
				})
			},
		}
	};
</script>
<style lang="scss" scoped>
	.total_info {
		width: 100%;
		height: 96rpx;
		background: #fff;
		border: 1px solid #E2E2E2;
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 10;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 36rpx;
		.total_le {
			display: flex;
			align-items: center;
			font-size: 28rpx;
			image {
				width: 48rpx;
				height: 48rpx;
				margin-right: 10rpx;
			}
			
		}
		.total_ri {
			width: 200rpx;
			height: 70rpx;
			background: #E60012;
			border-radius: 16rpx;
			font-size: 28rpx;
			color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
	.select_icon {
		width: 72rpx;
		height: 48rpx;
		padding-right: 16rpx;
		image {
			width: 48rpx;
			height: 48rpx;
		}
	}
	.title_text {
		color: #439AEC;
		font-size: 32rpx;
	}
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: #f6f7f9;
		background-size: 100% auto;
	}

	.rateLearn_flex_0 {
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.rateLearn_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333333;
	}

	.rateLearn_fd0_0_c0_c0 {
		font-size: 36rpx;
		color: #333;
	}

	.rateLearn_fd0_0_c0 {
		width: 120rpx;
	}

	.rateLearn_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.rateLearn_titlefd1_0_c5 {
		margin: 0rpx 85rpx 0rpx 0rpx;
	}

	.rateLearn_titlefd1_0_c4 {
		margin: 0rpx 52rpx 0rpx 0rpx;
	}

	.rateLearn_titlefd1_0_c3 {
		margin: 0rpx 62rpx 0rpx 102rpx;
	}

	.rateLearn_linefd1_0 {
		background: #E60012;
		width: 80rpx;
		height: 4rpx;
		top: 86rpx;
		background-size: 100% auto !important;
		border-radius: 30rpx;
	}

	.checkTitlefd1_0 {
		font-weight: 500 !important;
		font-size: 28rpx !important;
		color: #E60012 !important;
		background-color: rgba(255, 255, 255, 1) !important;
	}

	::v-deep .rateLearn_benbenTabsfd1_0 {
		background: #fff;
		width: 100%;
		height: 90rpx;
		white-space: nowrap;
		text-align: center;
		font-size: 28rpx;
		font-weight: 400;
		color: rgba(153, 153, 153, 1);
	}

	.rateLearn_flex_2 {
		background: #FFFFFF;
		border-radius: 24rpx 24rpx 0rpx 0rpx;
		padding: 41rpx 24rpx 40rpx 24rpx;
	}

	.rateLearn_fd2_3 {
		background: var(--benbenbgColor5);
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 32rpx;
		color: rgba(102, 102, 102, 1);
		width: 686rpx;
		height: 80rpx;
		line-height: 80rpx;
		margin: 0rpx 8rpx 0rpx 8rpx;
	}

	.rateLearn_fd2_2 {
		background: var(--benbenbgColor2);
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 32rpx;
		color: var(--benbenFontColor3);
		width: 686rpx;
		height: 80rpx;
		line-height: 80rpx;
		margin: 56rpx 8rpx 24rpx 8rpx;
	}

	.rateLearn_fd2_1_c0_c0_c1_c1_c1_c1 {
		color: #666666;
		font-size: 28rpx;
		font-weight: 400;
		line-height: 40rpx;
		margin: 0rpx 0rpx 0rpx 12rpx;
	}

	.rateLearn_fd2_1_c0_c0_c1_c1_c1_c0 {
		width: 30rpx;
		height: 30rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.rateLearn_fd2_1_c0_c0_c1_c1_c0_c1 {
		margin: 8rpx 0rpx 0rpx 0rpx;
	}

	.rateLearn_fd2_1_c0_c0_c1_c1_c0_c0_c1 {
		color: #999999;
		font-size: 24rpx;
		font-weight: 400;
		line-height: 33rpx;
		margin: 0rpx 0rpx 0rpx 10rpx;
	}

	.rateLearn_fd2_1_c0_c0_c1_c1_c0_c0_c0 {
		color: #999999;
		font-size: 24rpx;
		font-weight: 400;
		line-height: 33rpx;
	}

	.rateLearn_fd2_1_c0_c0_c1_c1 {
		margin: 16rpx 0rpx 0rpx 0rpx;
	}

	.rateLearn_fd2_1_c0_c0_c1_c0_c2_c0_1 {
		color: #B82441;
		font-size: 24rpx;
		font-weight: 400;
		line-height: 33rpx;
	}

	.rateLearn_fd2_1_c0_c0_c1_c0_c2_c0 {
		color: var(--benbenFontColor5);
		font-size: 24rpx;
		font-weight: 400;
		line-height: 33rpx;
	}

	.rateLearn_fd2_1_c0_c0_c1_c0_c2 {
		background: var(--benbenbgColor8);
		margin: 0rpx 0rpx 0rpx auto;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		padding: 0rpx 8rpx 0rpx 8rpx;
	}

	.rateLearn_fd2_1_c0_c0_c1_c0_c1 {
		width: 64rpx;
		height: 33rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 0rpx 0rpx 0rpx 16rpx;
	}

	.rateLearn_fd2_1_c0_c0_c1_c0_c0 {
		color: #333333;
		font-size: 28rpx;
		font-weight: 500;
		line-height: 40rpx;
	}

	.rateLearn_fd2_1_c0_c0_c1 {
		margin: 0rpx 0rpx 0rpx 32rpx;
	}

	.rateLearn_fd2_1_c0_c0_c0 {
		width: 32rpx;
		height: 32rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.rateLearn_fd2_1_c0_c0 {
		background: #F8F8F8;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 32rpx 32rpx 32rpx 32rpx;
		margin: 32rpx 0rpx 0rpx 0rpx;
	}

	.rateLearn_fd2_1 {
		touch-action: none;
		height: 500rpx;
	}

	.rateLearn_fd2_0_c3 {
		width: 40rpx;
		height: 40rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		position: absolute;
		top: -16rpx;
		right: 0rpx;
	}

	.rateLearn_fd2_0_c1 {
		color: #333333;
		font-size: 36rpx;
		font-weight: 500;
		line-height: 50rpx;
		margin: 0rpx 24rpx 0rpx 24rpx;
	}

	.rateLearn_fd2_0_c0 {
		width: 32rpx;
		height: 10rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.rateLearn_fd2_0 {
		position: relative;
	}

	.rateLearn_flex_3 {
		padding: 32rpx 36rpx 0rpx 36rpx;
	}

	.rateLearn_fd3_0_c1_c1_c1 {
		background: #999999;
		width: 2rpx;
		height: 27rpx;
		margin: 0rpx 20rpx 0rpx 20rpx;
		transform: scaleX(0.5);
	}

	.rateLearn_fd3_0_c1_c1_c0 {
		font-size: 24rpx;
		color: rgba(153, 153, 153, 1);
	}

	.rateLearn_fd3_0_c1_c1 {
		margin: 18rpx 0rpx 0rpx 0rpx;
	}

	.rateLearn_fd3_0_c1_c0_c0 {
		font-size: 28rpx;
		-webkit-line-clamp: 2;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}

	.rateLearn_fd3_0_c1 {
		margin: 0rpx 0rpx 0rpx 32rpx;
	}

	.rateLearn_fd3_0_c0_c1 {
		width: 250rpx;
		height: 168rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.rateLearn_fd3_0_c0_c0_c0 {
		font-size: 28rpx;
	}

	.rateLearn_fd3_0_c0_c0 {
		background: rgba(0, 0, 0, 0.5);
		width: 100%;
		height: 45rpx;
		background-size: 100% auto;
		color: var(--benbenFontColor3);
		font-size: 24rpx;
		position: absolute;
		left: 0rpx;
		bottom: 0rpx;
		z-index: 10;
	}

	.rateLearn_fd3_0_c0 {
		position: relative;
		border-radius: 16rpx;
		overflow: hidden;
	}

	.rateLearn_fd3_0 {
		background: #fff;
		background-size: 100% auto;
		border-radius: 16rpx;
		padding: 28rpx 32rpx 28rpx 32rpx;
		margin: 0rpx 0rpx 24rpx 0rpx;
	}
</style>